home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / socket / miami3 / miamisdk / netinclude / sys / socket.h < prev    next >
C/C++ Source or Header  |  1998-05-24  |  9KB  |  307 lines

  1. #ifndef _SYS_SOCKET_H_
  2. #define    _SYS_SOCKET_H_
  3.  
  4. #ifndef _SYS_TYPES_H_
  5. #include <sys/types.h>
  6. #endif
  7.  
  8. #define FD_ACCEPT     0x001    /* there is a connection to accept() */
  9. #define FD_CONNECT     0x002    /* connect() completed */
  10. #define FD_OOB         0x004    /* socket has out-of-band data */
  11. #define FD_READ         0x008    /* socket is readable */
  12. #define FD_WRITE     0x010    /* socket is writeable */
  13. #define FD_ERROR     0x020    /* asynchronous error on socket */
  14. #define FD_CLOSE     0x040    /* connection closed (graceful or not) */
  15.  
  16.  
  17. /*
  18.  * Definitions related to sockets: types, address families, options.
  19.  */
  20.  
  21. /*
  22.  * Types
  23.  */
  24. #define    SOCK_STREAM    1        /* stream socket */
  25. #define    SOCK_DGRAM    2        /* datagram socket */
  26. #define    SOCK_RAW    3        /* raw-protocol interface */
  27. #define    SOCK_RDM    4        /* reliably-delivered message */
  28. #define    SOCK_SEQPACKET    5        /* sequenced packet stream */
  29.  
  30. /*
  31.  * Option flags per-socket.
  32.  */
  33. #define    SO_DEBUG    0x0001        /* turn on debugging info recording */
  34. #define    SO_ACCEPTCONN    0x0002        /* socket has had listen() */
  35. #define    SO_REUSEADDR    0x0004        /* allow local address reuse */
  36. #define    SO_KEEPALIVE    0x0008        /* keep connections alive */
  37. #define    SO_DONTROUTE    0x0010        /* just use interface addresses */
  38. #define    SO_BROADCAST    0x0020        /* permit sending of broadcast msgs */
  39. #define    SO_USELOOPBACK    0x0040        /* bypass hardware when possible */
  40. #define    SO_LINGER    0x0080        /* linger on close if data present */
  41. #define    SO_OOBINLINE    0x0100        /* leave received OOB data in line */
  42. #define    SO_REUSEPORT    0x0200        /* allow local address & port reuse */
  43.  
  44. /*
  45.  * Additional options, not kept in so_options.
  46.  */
  47. #define SO_SNDBUF    0x1001        /* send buffer size */
  48. #define SO_RCVBUF    0x1002        /* receive buffer size */
  49. #define SO_SNDLOWAT    0x1003        /* send low-water mark */
  50. #define SO_RCVLOWAT    0x1004        /* receive low-water mark */
  51. #define SO_SNDTIMEO    0x1005        /* send timeout */
  52. #define SO_RCVTIMEO    0x1006        /* receive timeout */
  53. #define    SO_ERROR    0x1007        /* get error status and clear */
  54. #define    SO_TYPE        0x1008        /* get socket type */
  55.  
  56. #define SO_EVENTMASK    0x2001
  57.  
  58. /*
  59.  * Structure used for manipulating linger option.
  60.  */
  61. struct    linger {
  62.     long    l_onoff;        /* option on/off */
  63.     long    l_linger;        /* linger time */
  64. };
  65.  
  66. /*
  67.  * Level number for (get/set)sockopt() to apply to socket itself.
  68.  */
  69. #define    SOL_SOCKET    0xffff        /* options for socket level */
  70.  
  71. /*
  72.  * Address families.
  73.  */
  74. #define    AF_UNSPEC    0        /* unspecified */
  75. #define    AF_LOCAL    1        /* local to host (pipes, portals) */
  76. #define    AF_UNIX        AF_LOCAL    /* backward compatibility */
  77. #define    AF_INET        2        /* internetwork: UDP, TCP, etc. */
  78. #define    AF_IMPLINK    3        /* arpanet imp addresses */
  79. #define    AF_PUP        4        /* pup protocols: e.g. BSP */
  80. #define    AF_CHAOS    5        /* mit CHAOS protocols */
  81. #define    AF_NS        6        /* XEROX NS protocols */
  82. #define    AF_ISO        7        /* ISO protocols */
  83. #define    AF_OSI        AF_ISO
  84. #define    AF_ECMA        8        /* european computer manufacturers */
  85. #define    AF_DATAKIT    9        /* datakit protocols */
  86. #define    AF_CCITT    10        /* CCITT protocols, X.25 etc */
  87. #define    AF_SNA        11        /* IBM SNA */
  88. #define AF_DECnet    12        /* DECnet */
  89. #define AF_DLI        13        /* DEC Direct data link interface */
  90. #define AF_LAT        14        /* LAT */
  91. #define    AF_HYLINK    15        /* NSC Hyperchannel */
  92. #define    AF_APPLETALK    16        /* Apple Talk */
  93. #define    AF_ROUTE    17        /* Internal Routing Protocol */
  94. #define    AF_LINK        18        /* Link layer interface */
  95. #define    pseudo_AF_XTP    19        /* eXpress Transfer Protocol (no AF) */
  96. #define    AF_COIP        20        /* connection-oriented IP, aka ST II */
  97. #define    AF_CNT        21        /* Computer Network Technology */
  98. #define pseudo_AF_RTIP    22        /* Help Identify RTIP packets */
  99. #define    AF_IPX        23        /* Novell Internet Protocol */
  100. #define    AF_SIP        24        /* Simple Internet Protocol */
  101. #define    pseudo_AF_PIP    25        /* Help Identify PIP packets */
  102. #define    AF_ISDN        26        /* Integrated Services Digital Network*/
  103. #define    AF_E164        AF_ISDN        /* CCITT E.164 recommendation */
  104. #define    pseudo_AF_KEY    27        /* Internal key-management function */
  105. #define    AF_INET6    28        /* IPv6 */
  106.  
  107. #define    AF_MAX        29
  108.  
  109. /*
  110.  * Structure used by kernel to store most
  111.  * addresses.
  112.  */
  113. struct sockaddr {
  114.     u_char    sa_len;            /* total length */
  115.     u_char    sa_family;        /* address family */
  116.     char    sa_data[14];        /* actually longer; address value */
  117. };
  118.  
  119. /*
  120.  * Structure used by kernel to pass protocol
  121.  * information in raw sockets.
  122.  */
  123. struct sockproto {
  124.     u_short    sp_family;        /* address family */
  125.     u_short    sp_protocol;        /* protocol */
  126. };
  127.  
  128. /*
  129.  * Protocol families, same as address families for now.
  130.  */
  131. #define    PF_UNSPEC    AF_UNSPEC
  132. #define    PF_LOCAL    AF_LOCAL
  133. #define    PF_UNIX        PF_LOCAL    /* backward compatibility */
  134. #define    PF_INET        AF_INET
  135. #define    PF_IMPLINK    AF_IMPLINK
  136. #define    PF_PUP        AF_PUP
  137. #define    PF_CHAOS    AF_CHAOS
  138. #define    PF_NS        AF_NS
  139. #define    PF_ISO        AF_ISO
  140. #define    PF_OSI        AF_ISO
  141. #define    PF_ECMA        AF_ECMA
  142. #define    PF_DATAKIT    AF_DATAKIT
  143. #define    PF_CCITT    AF_CCITT
  144. #define    PF_SNA        AF_SNA
  145. #define PF_DECnet    AF_DECnet
  146. #define PF_DLI        AF_DLI
  147. #define PF_LAT        AF_LAT
  148. #define    PF_HYLINK    AF_HYLINK
  149. #define    PF_APPLETALK    AF_APPLETALK
  150. #define    PF_ROUTE    AF_ROUTE
  151. #define    PF_LINK        AF_LINK
  152. #define    PF_XTP        pseudo_AF_XTP    /* really just proto family, no AF */
  153. #define    PF_COIP        AF_COIP
  154. #define    PF_CNT        AF_CNT
  155. #define    PF_SIP        AF_SIP
  156. #define    PF_IPX        AF_IPX        /* same format as AF_NS */
  157. #define PF_RTIP        pseudo_AF_FTIP    /* same format as AF_INET */
  158. #define PF_PIP        pseudo_AF_PIP
  159. #define    PF_ISDN        AF_ISDN
  160.  
  161. #define    PF_MAX        AF_MAX
  162.  
  163. /*
  164.  * Definitions for network related sysctl, CTL_NET.
  165.  *
  166.  * Second level is protocol family.
  167.  * Third level is protocol number.
  168.  *
  169.  * Further levels are defined by the individual families below.
  170.  */
  171. #define NET_MAXID    AF_MAX
  172.  
  173. #define CTL_NET_NAMES { \
  174.     { 0, 0 }, \
  175.     { 0, 0 }, \
  176.     { "inet", CTLTYPE_NODE }, \
  177.     { 0, 0 }, \
  178.     { 0, 0 }, \
  179.     { 0, 0 }, \
  180.     { 0, 0 }, \
  181.     { 0, 0 }, \
  182.     { 0, 0 }, \
  183.     { 0, 0 }, \
  184.     { 0, 0 }, \
  185.     { 0, 0 }, \
  186.     { 0, 0 }, \
  187.     { 0, 0 }, \
  188.     { 0, 0 }, \
  189.     { 0, 0 }, \
  190.     { 0, 0 }, \
  191.     { "route", CTLTYPE_NODE }, \
  192.     { "link_layer", CTLTYPE_NODE }, \
  193.     { 0, 0 }, \
  194.     { 0, 0 }, \
  195.     { 0, 0 }, \
  196.     { 0, 0 }, \
  197.     { 0, 0 }, \
  198.     { 0, 0 }, \
  199.     { 0, 0 }, \
  200. }
  201.  
  202. /*
  203.  * PF_ROUTE - Routing table
  204.  *
  205.  * Three additional levels are defined:
  206.  *    Fourth: address family, 0 is wildcard
  207.  *    Fifth: type of info, defined below
  208.  *    Sixth: flag(s) to mask with for NET_RT_FLAGS
  209.  */
  210. #define NET_RT_DUMP    1        /* dump; may limit to a.f. */
  211. #define NET_RT_FLAGS    2        /* by flags, e.g. RESOLVING */
  212. #define NET_RT_IFLIST    3        /* survey interface list */
  213. #define    NET_RT_MAXID    4
  214.  
  215. #define CTL_NET_RT_NAMES { \
  216.     { 0, 0 }, \
  217.     { "dump", CTLTYPE_STRUCT }, \
  218.     { "flags", CTLTYPE_STRUCT }, \
  219.     { "iflist", CTLTYPE_STRUCT }, \
  220. }
  221.  
  222. /*
  223.  * Maximum queue length specifiable by listen.
  224.  */
  225. #define    SOMAXCONN    128
  226.  
  227. /*
  228.  * Message header for recvmsg and sendmsg calls.
  229.  * Used value-result for recvmsg, value only for sendmsg.
  230.  */
  231. struct msghdr {
  232.     caddr_t    msg_name;        /* optional address */
  233.     u_int    msg_namelen;        /* size of address */
  234.     struct    iovec *msg_iov;        /* scatter/gather array */
  235.     u_int    msg_iovlen;        /* # elements in msg_iov */
  236.     caddr_t    msg_control;        /* ancillary data, see below */
  237.     u_int    msg_controllen;        /* ancillary data buffer len */
  238.     long    msg_flags;        /* flags on received message */
  239. };
  240.  
  241. #define    MSG_OOB        0x1        /* process out-of-band data */
  242. #define    MSG_PEEK    0x2        /* peek at incoming message */
  243. #define    MSG_DONTROUTE    0x4        /* send without using routing tables */
  244. #define    MSG_EOR        0x8        /* data completes record */
  245. #define    MSG_TRUNC    0x10        /* data discarded before delivery */
  246. #define    MSG_CTRUNC    0x20        /* control data lost before delivery */
  247. #define    MSG_WAITALL    0x40        /* wait for full request or error */
  248. #define    MSG_DONTWAIT    0x80        /* this message should be nonblocking */
  249. #define    MSG_EOF        0x100        /* data completes connection */
  250. #define MSG_COMPAT      0x8000        /* used in sendit() */
  251.  
  252. /*
  253.  * Header for ancillary data objects in msg_control buffer.
  254.  * Used for additional information with/about a datagram
  255.  * not expressible by flags.  The format is a sequence
  256.  * of message elements headed by cmsghdr structures.
  257.  */
  258. struct cmsghdr {
  259.     u_int    cmsg_len;        /* data byte count, including hdr */
  260.     long    cmsg_level;        /* originating protocol */
  261.     long    cmsg_type;        /* protocol-specific type */
  262. /* followed by    u_char  cmsg_data[]; */
  263. };
  264.  
  265. /* given pointer to struct cmsghdr, return pointer to data */
  266. #define    CMSG_DATA(cmsg)        ((u_char *)((cmsg) + 1))
  267.  
  268. /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
  269. #define    CMSG_NXTHDR(mhdr, cmsg)    \
  270.     (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
  271.         (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
  272.         (struct cmsghdr *)NULL : \
  273.         (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
  274.  
  275. #define    CMSG_FIRSTHDR(mhdr)    ((struct cmsghdr *)(mhdr)->msg_control)
  276.  
  277. /* "Socket"-level control message types: */
  278. #define    SCM_RIGHTS    0x01        /* access rights (array of int) */
  279.  
  280. /*
  281.  * 4.3 compat sockaddr, move to compat file later
  282.  */
  283. struct osockaddr {
  284.     u_short    sa_family;        /* address family */
  285.     char    sa_data[14];        /* up to 14 bytes of direct address */
  286. };
  287.  
  288. /*
  289.  * 4.3-compat message header (move to compat file later).
  290.  */
  291. struct omsghdr {
  292.     caddr_t    msg_name;        /* optional address */
  293.     long    msg_namelen;        /* size of address */
  294.     struct    iovec *msg_iov;        /* scatter/gather array */
  295.     long    msg_iovlen;        /* # elements in msg_iov */
  296.     caddr_t    msg_accrights;        /* access rights sent/received */
  297.     long    msg_accrightslen;
  298. };
  299.  
  300. #ifndef    SHUT_RD            /* these three Posix.1g names are quite new */
  301. #define    SHUT_RD        0    /* shutdown for reading */
  302. #define    SHUT_WR        1    /* shutdown for writing */
  303. #define    SHUT_RDWR    2    /* shutdown for reading and writing */
  304. #endif
  305.  
  306. #endif /* !_SYS_SOCKET_H_ */
  307.